﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ControleurWorkflow
{
    class CTRL_WF_AUTH_V1 : I_CTRL_WF
    {
        private FactoryMessage.STGMSG oMsg;

        public FactoryMessage.STGMSG exec(FactoryMessage.STGMSG oMsg)
        {
            FactoryMessage.STGMSG oSQL;
            System.Data.DataSet ds;
            int nbRows;

            ComposantMappage.MAPP_TB_PERSONNE personne = new ComposantMappage.MAPP_TB_PERSONNE();
            CoucheAccesDonnees.CAD cad = new CoucheAccesDonnees.CAD();

            oSQL = personne.select_login_psw(oMsg);

            oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", new object[] { (object)oSQL.Data[0], (object)"authentification" }, "", "", "", true, "");

            oMsg = cad.get_Rows(oMsg);
            oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", oMsg.Data, "", "", "", true, "");

            ds = (System.Data.DataSet)oMsg.Data[0];
            nbRows = ds.Tables["authentification"].Rows.Count;

            if (nbRows == 1)
            {
                this.oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", null, "Utilisateur authentifié", "", "", true, "tokenSecurity1234");
            }
            else
            {
                this.oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", null, "Utilisateur inconnu", "", "", false, "");
            }

            return this.oMsg;
        }
    }
}